package com.jindy.module.oaEvectionApproval.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.module.oaEvectionApproval.domain.SyEvectionTrip;
import com.jindy.module.oaEvectionApproval.service.ISyEvectionTripService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 出差申请Controller
 * 
 * @author jindy
 * @date 2023-05-31
 */
@RestController
@RequestMapping("/module/trip")
public class SyEvectionTripController extends BaseController
{
    @Autowired
    private ISyEvectionTripService syEvectionTripService;

    /**
     * 查询出差申请列表
     */
    @PreAuthorize("@ss.hasPermi('module:trip:list')")
    @GetMapping("/list")
    public TableDataInfo list(SyEvectionTrip syEvectionTrip)
    {
        startPage();
        List<SyEvectionTrip> list = syEvectionTripService.selectSyEvectionTripList(syEvectionTrip);
        return getDataTable(list);
    }

    /**
     * 导出出差申请列表
     */
    @PreAuthorize("@ss.hasPermi('module:trip:export')")
    @Log(title = "出差申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SyEvectionTrip syEvectionTrip)
    {
        List<SyEvectionTrip> list = syEvectionTripService.selectSyEvectionTripList(syEvectionTrip);
        ExcelUtil<SyEvectionTrip> util = new ExcelUtil<SyEvectionTrip>(SyEvectionTrip.class);
        util.exportExcel(response, list, "出差申请数据");
    }

    /**
     * 获取出差申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:trip:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(syEvectionTripService.selectSyEvectionTripById(id));
    }

    /**
     * 新增出差申请
     */
    @PreAuthorize("@ss.hasPermi('module:trip:add')")
    @Log(title = "出差申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SyEvectionTrip syEvectionTrip)
    {
        return toAjax(syEvectionTripService.insertSyEvectionTrip(syEvectionTrip));
    }

    /**
     * 修改出差申请
     */
    @PreAuthorize("@ss.hasPermi('module:trip:edit')")
    @Log(title = "出差申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SyEvectionTrip syEvectionTrip)
    {
        return toAjax(syEvectionTripService.updateSyEvectionTrip(syEvectionTrip));
    }

    /**
     * 删除出差申请
     */
    @PreAuthorize("@ss.hasPermi('module:trip:remove')")
    @Log(title = "出差申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(syEvectionTripService.deleteSyEvectionTripByIds(ids));
    }
}
